package com.appcenter.application.controller;


import com.appcenter.application.input.orguser.*;
import com.appcenter.application.service.OrgUserService;
import com.appcenter.jz.config.ErrorJsonResult;
import com.appcenter.jz.config.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("api/services/jzappcenter/orguser")
@Api("部门人员操作API")
public class OrgUserController {
    @Autowired
    OrgUserService orgUserService;

    @ApiOperation(value = "创建部门人员", notes = "创建部门人员",produces = "application/json")
    @PostMapping("/createorguser")
    public ResponseEntity<JsonResult> CreateOrgUser(@RequestBody CreateOrgUserInput input) throws Exception {
        //throw new ErrorJsonResult("1000001", "捕获异常信息");
        JsonResult r = new JsonResult();
        try {
            r.setResult(orgUserService.CreateOrgUser(input));
        } catch (ErrorJsonResult e) {
            r.setResult(e.getClass().getName() + ":" + e.getMessage());
            r.setError(e);
            e.printStackTrace();
            return ResponseEntity.status(500).body(r);
        }
        return ResponseEntity.ok(r);
    }


    @ApiOperation(value = "删除部门人员", notes = "删除部门人员",produces = "application/json")
    @PostMapping("/deleteorguser")
    public ResponseEntity<JsonResult> DeleteOrgUser(@RequestBody DeleteOrgUserInput input) throws Exception {
        //throw new ErrorJsonResult("1000001", "捕获异常信息");
        JsonResult r = new JsonResult();
        try {
            r.setResult(orgUserService.DeleteOrgUser(input));

        } catch (ErrorJsonResult e) {
            r.setResult(e.getClass().getName() + ":" + e.getMessage());
            r.setError(e);
            e.printStackTrace();
            return ResponseEntity.status(500).body(r);
        }
        return ResponseEntity.ok(r);
    }


    @ApiOperation(value = "修改部门人员", notes = "修改部门人员",produces = "application/json")
    @PostMapping("/editorguser")
    public ResponseEntity<JsonResult> EditOrgUser(@RequestBody EditOrgUserInput input) throws Exception {
        //throw new ErrorJsonResult("1000001", "捕获异常信息");
        JsonResult r = new JsonResult();
        try {
            r.setResult(orgUserService.EditOrgUser(input));
        } catch (ErrorJsonResult e) {
            r.setResult(e.getClass().getName() + ":" + e.getMessage());
            r.setError(e);
            e.printStackTrace();
            return ResponseEntity.status(500).body(r);
        }
        return ResponseEntity.ok(r);
    }

    @ApiOperation(value = "搜索部门人员", notes = "搜索部门人员",produces = "application/json")
    @PostMapping("/getorgusers")
    public ResponseEntity<JsonResult> GetOrgUsers(@RequestBody GetOrgUsersInput input) throws Exception {
        //throw new ErrorJsonResult("1000001", "捕获异常信息");
        JsonResult r = new JsonResult();

        try {
            input.setPenetrate(true);
            r.setResult(orgUserService.GetOrgUsers(input));
        } catch (ErrorJsonResult e) {
            r.setResult(e.getClass().getName() + ":" + e.getMessage());
            r.setError(e);
            e.printStackTrace();
            return ResponseEntity.status(500).body(r);
        }

        return ResponseEntity.ok(r);
    }

    @ApiOperation(value = "加载部门人员信息", notes = "加载部门人员信息",produces = "application/json")
    @PostMapping("/pageLoad")
    public ResponseEntity<JsonResult> pageLoad(@RequestBody PageLoadInput input) throws Exception {
        JsonResult r = new JsonResult();
        try {
            r.setResult(orgUserService.PageLoad(input));
        } catch (ErrorJsonResult e) {
            r.setResult(e.getClass().getName() + ":" + e.getMessage());
            r.setError(e);
            e.printStackTrace();
            return ResponseEntity.status(500).body(r);
        }
        return ResponseEntity.ok(r);
    }




    @ApiOperation(value = "创建部门", notes = "创建部门",produces = "application/json")
    @PostMapping("/createOrg")
    public ResponseEntity<JsonResult> CreateOrg(@RequestBody CreateOrgInput input) throws Exception {
        //throw new ErrorJsonResult("1000001", "捕获异常信息");
        JsonResult r = new JsonResult();

        try {
            r.setResult(orgUserService.CreateOrg(input));
        } catch (ErrorJsonResult e) {
            r.setResult(e.getClass().getName() + ":" + e.getMessage());
            r.setError(e);
            e.printStackTrace();
            return ResponseEntity.status(500).body(r);
        }
        return ResponseEntity.ok(r);
    }


    @ApiOperation(value = "删除部门", notes = "删除部门",produces = "application/json")
    @PostMapping("/deleteOrg")
    public ResponseEntity<JsonResult> DeleteOrg(@RequestBody DeleteOrgInput input) throws Exception {
        //throw new ErrorJsonResult("1000001", "捕获异常信息");
        JsonResult r = new JsonResult();
        try {
            r.setResult(orgUserService.DeleteOrg(input));

        } catch (ErrorJsonResult e) {
            r.setResult(e.getClass().getName() + ":" + e.getMessage());
            r.setError(e);
            e.printStackTrace();
            return ResponseEntity.status(500).body(r);
        }
        return ResponseEntity.ok(r);
    }
    @ApiOperation(value = "修改部门", notes = "修改部门",produces = "application/json")
    @PostMapping("/editOrg")
    public ResponseEntity<JsonResult> EditOrg(@RequestBody EditOrgInput input) throws Exception {
        //throw new ErrorJsonResult("1000001", "捕获异常信息");
        JsonResult r = new JsonResult();
        try {
            r.setResult(orgUserService.EditOrg(input));
        } catch (ErrorJsonResult e) {
            r.setResult(e.getClass().getName() + ":" + e.getMessage());
            r.setError(e);
            e.printStackTrace();
            return ResponseEntity.status(500).body(r);
        }
        return ResponseEntity.ok(r);
    }

    @ApiOperation(value = "搜索部门", notes = "搜索部门",produces = "application/json")
    @PostMapping("/searchOrg")
    public ResponseEntity<JsonResult> searchOrg(@RequestBody SearchOrgInput input) throws Exception {
        //throw new ErrorJsonResult("1000001", "捕获异常信息");
        JsonResult r = new JsonResult();

        try {
            r.setResult(orgUserService.SearchOrg(input));
        } catch (ErrorJsonResult e) {
            r.setResult(e.getClass().getName() + ":" + e.getMessage());
            r.setError(e);
            e.printStackTrace();
            return ResponseEntity.status(500).body(r);
        }

        return ResponseEntity.ok(r);
    }

}
